var _contextPath;

$(document).ready(function() {
	list();
});

window.top["reload_rechargecard_list"]=function(){
	$('#rechargecard_list').datagrid( "load");
};

/**
 * 查询用户列表
 */
function list() {
	_contextPath = $("#contextPath").val();
	$("#rechargecard_list").datagrid(
			{
				queryParams : {
					pid : $("#menuText").val()
							&& $("#menuText").val() != null ? $("#menuText")
							.val() : "1"
				},
				columns : [ [{
					field : 'companyMenuId',
					title : '栏目ID',
					width : 100
				}, {
					field : 'pid',
					title : '父级栏目ID',
					width : 100
				}, {
					field : 'menuText',
					title : '栏目名称',
					width : 100
				},{
					field : 'menuUrl',
					title : '栏目地址',
					width : 100
				}] ],
				
				autoRowHeight : true,
				fitColumns : true,
				pagination : true,
				rownumbers : true,
				checkOnSelect : false,
				selectOnCheck : false,
				singleSelect : true
			});
}

function getContextPath() {
	if ("" == _contextPath) {
		_contextPath = $("#contextPath").val();
	}
	return _contextPath;
}

/**
 * 搜索
 * 
 * @return
 */
function searchKey() {
	$('#rechargecard_list').datagrid('load', {
		pid : $("#menuText").val() 
	});
}

/**
 * 新增
 */
function add(obj) {
	var backHtml = $(obj).html();
	$(obj).html('充值卡管理-新增');
	$(obj).attr('hiddenhref', getContextPath() + "iccard/rechargecard/toAddView");
	window.parent.menuClick(obj);
	$(obj).html(backHtml);
}

/**
 * 多选删除
 * 
 * @return
 */
function removeCard() {
	var rows = $("#rechargecard_list").datagrid("getChecked");
	if (rows.length > 0) {
		var ids = [];
		uppDialog.confirm(uppDialog.deleteMsgConfirm, function() {
			for ( var i = 0; i < rows.length; i++) {
				if(rows[i].rechargeableCardStatus=='0'){
					ids.push(rows[i].rechargeableCardId);
				}
			}
			$.ajax({
				url : getContextPath() + 'iccard/rechargecard/removeCard',
				data : {
					cardIds : ids.join(',')
				},
				type : 'POST',
				success : function(data) {
					top.uppShow(data.msgDesc);
					if ('0' == data.opResult) {
						window.location.href = getContextPath()
								+ "iccard/rechargecard/toListView";
					}
				}
			});
		});
		
	} else {
		top.uppShow(uppDialog.selectMsgUnselect);
	}
}

function removeC(rechargeableCardId) {
	uppDialog.confirm(uppDialog.deleteMsgConfirm, function() {
	$.ajax({
		url : getContextPath() + 'iccard/rechargecard/remove',
		data : {
			rechargeableCardId : rechargeableCardId
		},
		type : 'POST',
		success : function(data) {
			top.uppShow(data.msgDesc);
			if ('0' == data.opResult) {
				window.location.href = getContextPath()
						+ "iccard/rechargecard/toListView";
			}
		}
	});
});
	
	
}


